﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using Xceed.Wpf.Toolkit.Primitives;

namespace DocMreoLiteVersion.Controls
{

    //Конвертер значений даты в строку, выводящей только год!
    class DateToStringConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parametr, System.Globalization.CultureInfo culture)
        {
            if (value == null || value == "____")
                return null;
            DateTime dateTimeValue = (DateTime)value;
            return dateTimeValue.Year.ToString("0000");
        }

        public object ConvertBack(object value, Type targetType, object parametr, System.Globalization.CultureInfo culture)
        {

            String yearString = value as String;
            DateTime dateTime = new DateTime();
            try
            {
                if (value != null)
                    dateTime = DateTime.Parse(String.Format("01.01.{0}", yearString));
            }
            catch (Exception)
            {

                return null;
            }

            return dateTime;
        }
    }
}
